package module.admin;

import bean.Admin;
import util.actionListener.MouseEnterAction;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Author leiHua
 * @Date 2022/5/25 19:35
 */
public class AdminHead extends JPanel {
    public static int height=120;
    public AdminHead(){
        int width = AdminView.jframeWidth; //窗口宽度
        int height=100;
        this.setLayout(null);
        Color color = new Color(223, 249, 251);
        //标题label
        JLabel title = new JLabel("运动会后台管理");
        title.setFont(new Font("宋体",Font.BOLD,42));
        title.setBounds(150,20,400,60);
        title.setForeground(color);

        //欢迎admin组件
        JLabel adminLabel = new JLabel("欢迎，"+ Admin.myName);
        adminLabel.setFont(new Font("宋体",Font.TYPE1_FONT,24));
        adminLabel.setBounds(1000,50,150,40);
        adminLabel.setForeground(color);

        //退出按钮组件


        JButton exit = new JButton("退出");
        exit.setFont(new Font("宋体",Font.TYPE1_FONT,24));
        exit.setFocusPainted(false);
        exit.setBounds(1150,50,90,40);
        exit.setOpaque(false);
        exit.addMouseListener(new MouseEnterAction(exit));
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JLabel label = new JLabel("确定退出系统吗");
                label.setFont(new Font("宋体",Font.BOLD,30));
                //JOptionPane.showMessageDialog(null,label,"重复报名",JOptionPane.ERROR_MESSAGE);
                int i = JOptionPane.showConfirmDialog(null, label, "退出系统", JOptionPane.OK_CANCEL_OPTION);
                if(i==0){
                    System.exit(0);
                }
            }
        });


        this.setOpaque(false);
        this.add(adminLabel);
        this.add(title);
        this.add(exit);
        this.setBounds(0,0,width,height);

    }

}
